package com.macro.client.controller;

import com.macro.client.service.AddressService;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.UmsMemberReceiveAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName AddressController
 * @Description 描述
 * @Author bai
 * @Date 2024/10/23 10:03
 */

@RestController
@RequestMapping("address")
public class AddressController {

    @Autowired
    private AddressService addressService;


    /**
     * 地址列表
     */
    @GetMapping("/list")
    public CommonResult<List<UmsMemberReceiveAddress>> list(){
        List<UmsMemberReceiveAddress> list = addressService.list();
        return CommonResult.success(list);
    }

    /**
     * 解析字符串为收货地址
     * @param addr
     * @return
     */
    @PostMapping("/string2Addr/{addr}")
    public CommonResult string2Addr(@PathVariable String addr){
        UmsMemberReceiveAddress address=addressService.string2Addr(addr);
        return CommonResult.success(address);
    }


    /**
     * 添加
     */
    @PostMapping("/add")
    public CommonResult add(@RequestBody UmsMemberReceiveAddress UmsMemberReceiveAddress){
        addressService.add(UmsMemberReceiveAddress);
        return CommonResult.success(null,"添加成功");
    }

    /**
     * 根据id回显
     */
    @GetMapping("/{id}")
    public CommonResult find(@PathVariable Integer id){
        UmsMemberReceiveAddress umsMemberReceiveAddress = addressService.find(id);
        return CommonResult.success(umsMemberReceiveAddress);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public CommonResult update(@RequestBody UmsMemberReceiveAddress umsMemberReceiveAddress){
         addressService.update(umsMemberReceiveAddress);
        return CommonResult.success(null,"修改");
    }

    /**
     * 删除
     */
    @PostMapping("/delete/{id}")
    public CommonResult delete(@PathVariable Integer id){
        addressService.delete(id);
        return CommonResult.success(null,"删除成功");
    }


}
